﻿#region Copyright © 2013 Paul Miller (Millz)
// All rights are reserved. Reproduction or transmission in whole or in part,
// any form or by any means, electronic, mechanical or otherwise, is prohibited
// without the prior written consent of the copyright owner.
// 
// Filename: InsanitySettings.cs
// Date:     23/09/2013
// Author:   Paul Miller (Millz)
#endregion
using System.IO;
using System.Windows.Forms;
using System.Xml.Linq;
using Insanity.Helpers;
using Styx;
using Styx.Common;
using Styx.Helpers;

namespace Insanity.Settings
{
    public class InsanitySettings : Styx.Helpers.Settings
    {
        public static readonly InsanitySettings Instance = new InsanitySettings();

        private InsanitySettings()
            : base(SettingsPath + ".xml")
        {
        }

        public static void SaveFile()
        {
            var saveFileDialog = new SaveFileDialog
                {
                    Filter = "Settings File|*.*",
                    Title = "Save Settings...",
                    InitialDirectory = string.Format("{0}\\Routines\\Insanity\\Settings\\", Utilities.AssemblyDirectory),
                    DefaultExt = "xml",
                    FileName = "Insanity - " + StyxWoW.Me.Name
                };
            var result = saveFileDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                Instance.SaveToFile(saveFileDialog.FileName);
                LogSettings();
                Log.Info("Settings Saved to File.");
            }
            else
            {
                Log.Info("Setting Save Cancelled.");
            }
        }

        public static void LoadFile(string filePath = null)
        {
            if (filePath == null)
            {
                var openFileDialog = new OpenFileDialog
                    {
                        Filter = "Settings File|*.*",
                        Title = "Load Settings...",
                        InitialDirectory =
                            string.Format("{0}\\Routines\\Insanity\\Settings\\", Utilities.AssemblyDirectory)
                    };
                openFileDialog.ShowDialog();

                if (!openFileDialog.FileName.EndsWith(".xml")) return;
                Instance.LoadFromXML(XElement.Load(openFileDialog.FileName));
                Log.Info("Loaded Settings From File.");
            }

            if (filePath != null)
            {
                //Log.Info("Loading File: {0}", filePath);
                if (File.Exists(filePath))
                {
                    Instance.LoadFromXML(XElement.Load(filePath));
                }

                Log.Info("Loaded Settings Using Quick Load.");
            }
        }

        private static string SettingsPath
        {
            get
            {
                return string.Format("{0}\\Settings\\Insanity\\Insanity_Active_Settings_{1}", Utilities.AssemblyDirectory,
                                     StyxWoW.Me.Name);
            }
        }

        public static void LogSettings()
        {
            Log.Debug("");
            Log.Debug("====== Insanity Settings ======");
            foreach (var kvp in Instance.GetSettings())
            {
                Log.Debug("+ {0}: {1}", kvp.Key, kvp.Value.ToString());
            }
            Log.Debug("==============================");
            Log.Debug("");
        }

        public void NonStaticLogSettings()
        {
            Log.Debug("");
            Log.Debug("====== Insanity Settings ======");
            foreach (var kvp in Instance.GetSettings())
            {
                Log.Debug("+ {0}: {1}", kvp.Key, kvp.Value.ToString());
            }
            Log.Debug("==============================");
            Log.Debug("");
        }
        
        #region Items

        [Setting, DefaultValue(true)]
        public bool UseHealthstones { get; set; }

        [Setting, DefaultValue(false)]
        public bool OnlyHealthstoneWithDarkRegen { get; set; }

        [Setting, DefaultValue(30)]
        public int HealthstoneHPPercent { get; set; }

        [Setting, DefaultValue(true)]
        public bool UseTrinket1 { get; set; }

        [Setting, DefaultValue(true)]
        public bool UseTrinket2 { get; set; }

        /* Trinket Condition States
        0 = Never
        1 = On Boss Or Player
        2 = On Cooldown
        3 = On Loss of Control
        4 = Low Health 
        5 = Low Mana
         */

        [Setting, DefaultValue(0)]
        public int Trinket1Condition { get; set; }

        [Setting, DefaultValue(0)]
        public int Trinket2Condition { get; set; }

        [Setting, DefaultValue(30)]
        public int Trinket1LowHPValue { get; set; }

        [Setting, DefaultValue(30)]
        public int Trinket1LowManaValue { get; set; }

        [Setting, DefaultValue(30)]
        public int Trinket2LowHPValue { get; set; }

        [Setting, DefaultValue(30)]
        public int Trinket2LowManaValue { get; set; }

        #endregion Items

        #region Professions
        /* Synapse Springs
        0 = Never
        1 = On Boss Or Player
        2 = On Cooldown
         */
        [Setting, DefaultValue(false)]
        public bool UseSynapseSprings { get; set; }

        [Setting, DefaultValue(0)]
        public int SynapseSpringsCond { get; set; }


         /* Lifeblood
         0 = On Low HP
         1 = On Boss Or Player
         2 = On Cooldown
         */
        [Setting, DefaultValue(false)]
        public bool UseLifeblood { get; set; }

        [Setting, DefaultValue(1)]
        public int LifebloodCond { get; set; }

        [Setting, DefaultValue(25)]
        public int LifebloodLowHPValue { get; set; }

        #endregion

        #region Racials
        [Setting, DefaultValue(1)]
        public int RacialUsage { get; set; }

        #endregion Racials

        #region Other

        
        #endregion

        #region General - Non Specialization Abilities

        [Setting, DefaultValue(true)]
        public bool UsePowerWordFortitude { get; set; }
        
        [Setting, DefaultValue(true)]
        public bool UseFadeToReduceThreat { get; set; }
        
        [Setting, DefaultValue(true)]
        public bool UseFearWard { get; set; }
        
        [Setting, DefaultValue(true)]
        public bool InnerFire { get; set; }

        [Setting, DefaultValue(false)]
        public bool InnerWill { get; set; }

        [Setting, DefaultValue(false)]
        public bool UsePoMLowHP { get; set; }

        [Setting, DefaultValue(80)]
        public int PoMLowHPValue { get; set; }

        [Setting, DefaultValue(true)]
        public bool AlwaysKeepPoMActive { get; set; }

        [Setting, DefaultValue(true)]
        public bool PsychicScreamTarget { get; set; }

        [Setting, DefaultValue(true)]
        public bool PsychicScreamAny { get; set; }
        
        [Setting, DefaultValue(true)]
        public bool UsePowerWordShieldLowHp { get; set; }

        [Setting, DefaultValue(30)]
        public int PowerWordShieldLowHPValue { get; set; }

        [Setting, DefaultValue(true)]
        public bool UseRenewLowHp { get; set; }

        [Setting, DefaultValue(90)]
        public int RenewLowHPValue { get; set; }
        
        [Setting, DefaultValue(true)]
        public bool LeapOfFaithLowHP { get; set; }

        [Setting, DefaultValue(10)]
        public int LeapOfFaithLowHPValue { get; set; }

        [Setting, DefaultValue(true)]
        public bool LeapOfFaithCrowdControl { get; set; }


        #endregion General - Non Specialization Abilities

        #region Talents

        // Tier 1
        [Setting, DefaultValue(true)]
        public bool UseVoidTendrilsOnTargetInRange { get; set; }
        
        [Setting, DefaultValue(true)]
        public bool PsyfiendOnCooldown { get; set; }
        
        // Tier 2
        [Setting, DefaultValue(true)]
        public bool BodyAndSoulInCombat { get; set; }

        [Setting, DefaultValue(true)]
        public bool BodyAndSoulNoCombat { get; set; }

        [Setting, DefaultValue(true)]
        public bool AngelicFeatherInCombat { get; set; }

        [Setting, DefaultValue(true)]
        public bool AngelicFeatherNoCombat { get; set; }
        
        [Setting, DefaultValue(true)]
        public bool FadeWhenSnaredRooted { get; set; }

        // Tier 3

        [Setting, DefaultValue(true)]
        public bool UseMindbender { get; set; }

        // Tier 4

        [Setting, DefaultValue(true)]
        public bool UseDesperatePrayer { get; set; }

        [Setting, DefaultValue(20)]
        public int DesperatePrayerHealthValue { get; set; }

        [Setting, DefaultValue(true)]
        public bool SpectralGuiseOnLowHP { get; set; }

        [Setting, DefaultValue(40)]
        public int SpectralGuiseLowHPValue { get; set; }

        /*
            On Cooldown
            On Boss Or Player
            On Target Low HP %
         */
        [Setting, DefaultValue(0)]
        public int PowerInfusionCondition { get; set; }

        [Setting, DefaultValue(60)]
        public int PowerInfusionLowHPValue { get; set; }


        // Tier 6
        [Setting, DefaultValue(true)]
        public bool UseCascade { get; set; }

        [Setting, DefaultValue(20)]
        public int CascadeMinDistance { get; set; }

        [Setting, DefaultValue(true)]
        public bool UseDivineStar { get; set; }

        [Setting, DefaultValue(true)]
        public bool UseHalo { get; set; }

        [Setting, DefaultValue(20)]
        public int HaloMinDistance { get; set; }

        [Setting, DefaultValue(30)]
        public int HaloMaxDistance { get; set; }

        #endregion Talents

        #region Shadow
        
        [Setting, DefaultValue(true)]
        public bool Shadow_EnableAoEAbilities { get; set; }

        [Setting, DefaultValue(3)]
        public int Shadow_AoEHighUnitCount { get; set; }

        [Setting, DefaultValue(3000)]
        public int Shadow_SWPForceRefreshTime { get; set; }

        [Setting, DefaultValue(5)]
        public int Shadow_SWPMaxDoTsToCast { get; set; }

        [Setting, DefaultValue(4500)]
        public int Shadow_VTForceRefreshTime { get; set; }

        [Setting, DefaultValue(3)]
        public int Shadow_VTMaxDoTsToCast { get; set; }

        [Setting, DefaultValue(true)]
        public bool Shadow_UseVampiricEmbrace { get; set; }

        [Setting, DefaultValue(80)]
        public int Shadow_VampiricEmbraceHealthPercent { get; set; }

        [Setting, DefaultValue(true)]
        public bool Shadow_VampiricEmbraceWaitForDP { get; set; }

        [Setting, DefaultValue(true)]
        public bool Shadow_Dispersion_LowHP { get; set; }

        [Setting, DefaultValue(20)]
        public int Shadow_Dispersion_LowHPValue { get; set; }

        [Setting, DefaultValue(true)]
        public bool Shadow_Dispersion_LowMana { get; set; }

        [Setting, DefaultValue(10)]
        public int Shadow_Dispersion_LowManaValue { get; set; }

        #endregion Shadow

        #region Other
        
        [Setting, DefaultValue(0)]
        public int HasGivenRep { get; set; }

        [Setting, DefaultValue(false)]
        public bool UsePotion { get; set; }

        [Setting, DefaultValue(0)]
        public int PotionCondition { get; set; }

        #endregion

      

    }
}
